(function(w) {
    // Full list of configuration options available here:
    // https://github.com/hakimel/reveal.js#configuration
    Reveal.initialize({
        controls: true,
        progress: true,
        history: true,
        center: true,

        theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
        transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none

        // Parallax scrolling
        // parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
        // parallaxBackgroundSize: '2100px 900px',

        // Optional libraries used to extend on reveal.js
        dependencies: [{
            src: 'lib/js/classList.js',
            condition: function() {
                return !document.body.classList;
            }
        }, {
            src: 'plugin/markdown/marked.js',
            condition: function() {
                return !!document.querySelector('[data-markdown]');
            }
        }, {
            src: 'plugin/markdown/markdown.js',
            condition: function() {
                return !!document.querySelector('[data-markdown]');
            }
        }, {
            src: 'plugin/highlight/highlight.js',
            async: true,
            callback: function() {
                hljs.initHighlightingOnLoad();
            }
        }, {
            src: 'plugin/zoom-js/zoom.js',
            async: true,
            condition: function() {
                return !!document.body.classList;
            }
        }, {
            src: 'plugin/notes/notes.js',
            async: true,
            condition: function() {
                return !!document.body.classList;
            }
        }]
    });

    function $(selector) {
        return w.document.querySelectorAll(selector);
    }

    NodeList.prototype.on = function(eventName, callback) {
        var nodeArray = [].slice.call(this);
        nodeArray.forEach(function(node){
            node.addEventListener(eventName, callback);
        });
    }

    function updateParams(url, type, value)
    {
        var qMarkPos = url.indexOf('?');
        if (qMarkPos !== -1) {
            var index = url.indexOf(type);
            if (index !== -1) {
                var regx = new RegExp(type + '=' + '\\w+', 'ig');
                url = url.replace(regx, type + '=' + value);
            } else {
                url += '&' + type + '=' + value;
            }
        } else if (qMarkPos === url.length - 1) {
            url += type + '=' + value;
        } else {
            url += '?' + type + '=' + value;
        }

        return url;
    }

    $('.settings a').on('click', function(){
        var orgHref = w.location.href;
        var newHref = orgHref;
        var type = this.getAttribute('data-type');
        var value = this.getAttribute('data-value');
        newHref = updateParams(orgHref, type, value);
        w.location.href = newHref;
    });

    Reveal.addEventListener('imagesShown', function() {
        console.log( '"customevent" has fired' );
    });
})(window);
